import java.util.LinkedList;
import java.util.Queue;

public class Elevator {
    private final int id;
    private int currentFloor;
    private Direction direction;
    private final Queue<Integer> targetFloors;

    public Elevator(int id) {
        this.id = id;
        this.currentFloor = 0;
        this.direction = Direction.IDLE;
        this.targetFloors = new LinkedList<>();
    }

    public void addTarget(int floor) {
        if (!targetFloors.contains(floor)) {
            targetFloors.add(floor);
        }
    }

    public void move() {
        if (targetFloors.isEmpty()) {
            direction = Direction.IDLE;
            return;
        }

        int target = targetFloors.peek();

        if (currentFloor < target) {
            currentFloor++;
            direction = Direction.UP;
        } else if (currentFloor > target) {
            currentFloor--;
            direction = Direction.DOWN;
        }

        if (currentFloor == target) {
            System.out.println("Elevator " + id + " arrived at floor " + currentFloor);
            targetFloors.poll();
        }
    }

    public boolean isIdle() {
        return direction == Direction.IDLE;
    }

    public int getCurrentFloor() {
        return currentFloor;
    }

    public Direction getDirection() {
        return direction;
    }

    public int getId() {
        return id;
    }
}
